package com.ktjy.examination.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ktjy.examination.entity.Users;
import com.ktjy.examination.mapper.UserMapper;
import com.ktjy.examination.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public int login(Users users) {
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userCode", users.getUserCode());
        queryWrapper.eq("password", users.getPassword());
        
        // 获取用户信息
        Users user = userMapper.selectOne(queryWrapper);
        if (user != null) {
            // 更新最后登录时间
            user.setLastLoginTime(new Date());
            userMapper.updateById(user);
            return 1;
        }
        return 0;
    }
}
